Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plan: use the inferred type as the column type in the schema #7624

Merged
merged 8 commits into from
Sep 12, 2018

Conversation

zz-jason
Copy link
Member

@zz-jason zz-jason commented Sep 5, 2018

What problem does this PR solve?

fix #7578
fix #7307

The type of the column in the schema should be reset after creating an aggregate function descriptor through the function aggregation.NewAggFuncDesc()

What is changed and how it works?

Check List

Tests

  • Unit test WIP
  • Integration test

Related changes

  • Need to be included in the release note

@zz-jason zz-jason added status/WIP type/bugfix This PR fixes a bug. sig/planner SIG: Planner labels Sep 5, 2018
@@ -594,6 +596,9 @@ func (b *planBuilder) buildDistinct(child LogicalPlan, length int) *LogicalAggre
}
plan4Agg.SetChildren(child)
plan4Agg.SetSchema(child.Schema().Clone())
for i, col := range plan4Agg.schema.Columns {
col.RetType = plan4Agg.AggFuncs[i].RetTp
}
// Distinct will be rewritten as first_row, we reset the type here since the return type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function already has this type update in next few lines.

first := aggregation.NewAggFuncDesc(agg.ctx, ast.AggFuncFirstRow, []expression.Expression{col}, false)
newAggFuncs = append(newAggFuncs, first)
outerPlan.Schema().Columns[i].RetType = first.RetTp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to modify the child schema directly? should we make a clone here?

@@ -115,7 +115,9 @@ func (b *planBuilder) buildAggregation(p LogicalPlan, aggFuncList []*ast.Aggrega
for _, col := range p.Schema().Columns {
newFunc := aggregation.NewAggFuncDesc(b.ctx, ast.AggFuncFirstRow, []expression.Expression{col}, false)
plan4Agg.AggFuncs = append(plan4Agg.AggFuncs, newFunc)
schema4Agg.Append(col)
newCol, _ := col.Clone().(*expression.Column)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So one column occurs in agg and agg' child. The tp of this two is different?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly. Actually, they are two columns if the type inferred after NewAggFuncDesc() is different from the origin type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since they are different, why unique id is the same one.

@zz-jason
Copy link
Member Author

@winoros @eurekaka @XuHuaiyu PTAL

Copy link
Contributor

@eurekaka eurekaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zz-jason zz-jason added the status/LGT1 Indicates that a PR has LGTM 1. label Sep 11, 2018
@zz-jason
Copy link
Member Author

/run-all-tests

@zz-jason
Copy link
Member Author

@winoros PTAL

@winoros
Copy link
Member

winoros commented Sep 12, 2018

@zz-jason Should we let the columns have same UniqueID have different fieldType? Or should we call Clone before ResolveIndices anymore?

@zz-jason
Copy link
Member Author

@winoros I think the UniqueID of a column should be carefully maintained case by case.

@zz-jason
Copy link
Member Author

/run-all-tests

@winoros
Copy link
Member

winoros commented Sep 12, 2018

@zz-jason Should we keep the firstRow function just like other agg func instead of unwarping the firstRow so the schema needs to change the column's fieldtype?

@winoros
Copy link
Member

winoros commented Sep 12, 2018

/run-common-test
/run-integration-common-test

Copy link
Member

@winoros winoros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

We need to carefully consider the UniqueID of the Column.

@lysu
Copy link
Contributor

lysu commented Sep 12, 2018

/run-common-test
/run-integration-common-test

@winoros
Copy link
Member

winoros commented Sep 12, 2018

I've figured out why new column cannot take effect easily. Will try to fix it when i have time.

@zz-jason zz-jason merged commit 7de83a3 into pingcap:master Sep 12, 2018
@zz-jason zz-jason deleted the dev/fix-firstrow-panic branch September 12, 2018 12:29
@zz-jason zz-jason added status/LGT2 Indicates that a PR has LGTM 2. status/all tests passed and removed status/LGT1 Indicates that a PR has LGTM 1. labels Sep 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/planner SIG: Planner status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

slice bounds out of range server crash on GROUP BY indexed enum
4 participants